package com.health.mapp.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.health.db.model.TrainingEnter;
import com.health.db.model.TrainingEnterExample;
import com.health.db.service.user.ITrainingEnterService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.QueryTrainingEnterReq;
import com.health.mapp.bean.QueryTrainingEnterResp;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;

/**
 * 查询已报名课程表
 * @author YC
 *
 */
public class QueryTrainingEnterImpl  implements ActionInterface{
	
	@Autowired
	ITrainingEnterService trainingEnterService;
	
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
		
		QueryTrainingEnterReq req = (QueryTrainingEnterReq) reqBean;
		QueryTrainingEnterResp _resp = new QueryTrainingEnterResp();
		
		TrainingEnterExample example = new TrainingEnterExample();
		
		if (StringUtils.isEmpty(req.getContactPhone())
				&&StringUtils.isEmpty(req.getOpenId())
				&&StringUtils.isEmpty(req.getOpenId2())
				&&StringUtils.isEmpty(req.getUnionId())
				)
		{
			//参数不足
			_resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ERROR);
			_resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ERROR_NOTE);
			return _resp;
			
		}
		
		
		//条件筛选
		if (StringUtils.isNotEmpty(req.getContactPhone())) {
			example.setContactPhone(req.getContactPhone());
		}else if (StringUtils.isNotEmpty(req.getOpenId())) {
			example.setOpenId(req.getOpenId());
		}else if (StringUtils.isNotEmpty(req.getOpenId2())) {
			example.setOpenId2(req.getOpenId2());
		}else if (StringUtils.isNotEmpty(req.getUnionId())) {
			example.setUnionId(req.getUnionId());
		}
		
		Integer pageNo=req.getPageNo();
		Integer pageSize=req.getPageNum();
		//判断页码
		if(null!=pageNo&&null!=pageSize){
			example.setOffset((pageNo.intValue()-1)*pageSize.intValue());
			example.setPageSize(pageSize.intValue());
		}
		
		List<TrainingEnter> baseList =trainingEnterService.selectByExample(example);
		
		_resp.setBaseList(baseList);
		
		_resp.setErrorCode(ResultCode.OPERATION_SUCCESS);
		_resp.setErrorMsg(ResultCode.OPERATION_SUCCESS_NOTE);
		
		return _resp;
	}

	public ITrainingEnterService getTrainingEnterService() {
		return trainingEnterService;
	}

	public void setTrainingEnterService(ITrainingEnterService trainingEnterService) {
		this.trainingEnterService = trainingEnterService;
	}
	
	
	
	

}
